#ifndef COMMON_H
#define COMMON_H

#include <openssl/evp.h>
#include <openssl/ec.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define MAX_BUFFER_SIZE 4096
#define SM4_KEY_SIZE 16
#define SM4_BLOCK_SIZE 16

// 错误处理
void handle_openssl_errors(void);

// 密钥文件路径
#define ALICE_PRIVATE_KEY "20231402lsh_private.pem"
#define ALICE_PUBLIC_KEY "20231402lsh_public.pem"
#define BOB_PRIVATE_KEY "20231414wsq_private.pem"
#define BOB_PUBLIC_KEY "20231414wsq_public.pem"

// 数字信封结构
typedef struct {
    unsigned char *ciphertext;  // SM4加密的密文
    size_t ciphertext_len;
    unsigned char *encrypted_key; // SM2加密的SM4密钥
    size_t encrypted_key_len;
    unsigned char *signature;   // SM2签名
    size_t signature_len;
} DigitalEnvelope;

#endif
